package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.QrtzCronTriggers;
import io.mybatis.example.springboot.service.QrtzCronTriggersService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * QRTZ_CRON_TRIGGERS - Cron类型的触发器表
 *
 * @author mkj
 */
@RestController
@RequestMapping("qrtzCronTriggerses")
public class QrtzCronTriggersController {

  @Autowired
  private QrtzCronTriggersService qrtzCronTriggersService;

  @PostMapping
  public DataResponse<QrtzCronTriggersDO> save(@RequestBody QrtzCronTriggersDO qrtzCronTriggers) {
    return DataResponse.ok(qrtzCronTriggersService.save( qrtzCronTriggers));
  }

  @GetMapping
  public RowsResponse<QrtzCronTriggersDO> findList(@RequestBody QrtzCronTriggersDO qrtzCronTriggers) {
    return RowsResponse.ok(qrtzCronTriggersService.findList( qrtzCronTriggers));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<QrtzCronTriggersDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzCronTriggersService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<QrtzCronTriggersDO> update(@PathVariable("id") Long id, @RequestBody QrtzCronTriggersDO qrtzCronTriggers) {
    qrtzCronTriggers.setId(id);
    return DataResponse.ok(qrtzCronTriggersService.update( qrtzCronTriggers));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzCronTriggersService.deleteById(id) == 1);
  }

}
